package com.k2data.test.testng.listener.interceptor;

import java.util.ArrayList;
import java.util.List;

import org.testng.IMethodInstance;
import org.testng.IMethodInterceptor;
import org.testng.ITestContext;

/**
 * IMethodInterceptor demo
 * @author wangchuan 2019-03-18
 *
 */
public class IMethodInterceptorListener implements IMethodInterceptor{
	public static final String DESC_KEY = "key";

	/**
	 * select method by description
	 */
	@Override
	public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
		List<IMethodInstance> result = new ArrayList<>();
		
		for(IMethodInstance method : methods) {
			String description = method.getMethod().getDescription();
			if(description != null && description.contains(DESC_KEY)) {
				result.add(method);
			}
		}
		
		return result;
	}

}
